package com.hxkj.controller.wechat;

import com.hxkj.domain.po.Applet;
import com.hxkj.domain.po.AppletUser;
import com.hxkj.domain.po.AuthUser;
import com.hxkj.service.wechat.AppletUserService;
import com.hxkj.token.annotation.LoginAuthor;
import com.hxkj.utils.Excelutil;
import com.platform.common.domain.result.ResultPageStruct;
import com.platform.common.domain.to.PageTo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 小程序用户控制器
 * <p>
 * Create by chenwei on 2018/6/14 15:15
 */
@RestController
@RequestMapping("/applet")
public class AppletUserController {

    @Resource
    private AppletUserService appletUserService;

    /**
     * 客户列表
     * @param appletUser
     * @return 翻页数据
     * @throws Exception
     */
    @RequiresPermissions("customer:view")
    @RequestMapping(value = "/user/getlist", method = RequestMethod.POST)
    ResultPageStruct<AppletUser> getlist(@ModelAttribute PageTo pageTo, @ModelAttribute AppletUser appletUser) throws Exception{
        return  appletUserService.getlist(pageTo,appletUser);
    }


    /**
     * 导出客户列表
     * @param appletUser
     * @return 翻页数据
     * @throws Exception
     */
    @RequiresPermissions("customer:view")
    @RequestMapping(value = "/user/export", method = RequestMethod.GET)
    void export(@ModelAttribute PageTo pageTo,@ModelAttribute AppletUser appletUser,HttpServletResponse response) throws Exception{
        List<Map<String,Object>> maps = appletUserService.export(pageTo,appletUser);
        if(maps.size() == 0){
            return;
        }else{
            Excelutil.buildXSLXExcel(maps, "客户列表", response);
        }
    }

    /**
     * 小程序列表下拉框
     * @return 翻页数据
     * @throws Exception;
     */
    @RequestMapping(value = "/user/getAppletsCombobox", method = RequestMethod.POST)
    List<Applet> getlist(@LoginAuthor AuthUser authUser) throws Exception {
        return appletUserService.getlist(authUser);
    }

    /****
     * 删除手机号
     *
     * @throws Exception
     * **/
    public void delete(@ModelAttribute AppletUser appletUser)throws Exception{
        appletUserService.delete(appletUser);
    }
}
